#!/bin/sh

# must not fail
set -e 

# debug
set -x 

echo "Starting $0"

INSTALL_INTO=/etc
FW2_DISTNAME=fw2-0.3.zip
FW2_DIRNAME=fw2-0.3
FW2_TARGET=fw2
FW2_UNPACKCMD=unzip


### copy to "install"

if [ ! -f ${DISTFILES_INSTALL}/${FW2_DISTNAME} ] ; then    
    echo "copying ${FW2_DISTNAME} to ${DISTFILES_INSTALL}"
    cp ${FW2_DISTNAME}     ${DISTFILES_INSTALL}
fi

### unpack if this version dont exist already
if [ -x ${INSTALL_INTO}/${FW2_DIRNAME} ] ;then
    echo "${FW2_DIRNAME} exists, skipping"
else

    cd ${INSTALL_INTO}
    ${FW2_UNPACKCMD} ${DISTFILES_INSTALL}/${FW2_DISTNAME} 
    if [ -x ${INSTALL_INTO}/${FW2_TARGET} ] ; do
	echo "${INSTALL_INTO}/${FW2_TARGET} exist, skipping"	
	exit
    else
	mv ${INSTALL_INTO}/${FW2_DIRNAME} ${INSTALL_INTO}/${FW2_TARGET}
    done
    cd -
fi



myIF=$(/sbin/ifconfig | egrep "^eth" | awk '{print $1}')
/etc/fw2/add-firewall-to-debian-interfaces.pl $myIF


# running firewall
${INSTALL_INTO}/${FW2_TARGET} $myIF

echo "End of $0"

